__author__ = 'wangleijie'
import sqlite3


# conn = sqlite3.connect("my.db");
# curs = conn.cursor();
# conn.commit();
# conn.close();



def convert(value):
    if value.startswith('-'):
        return value.strip('-');
    if not value:
        value = '0'
    return float(value)

conn = sqlite3.connect("food.db");
curs = conn.cursor();

curs.execute(
    '''
    create table food(
      id text,
      desc text,
      water text,
      kcal text ,
      protein text ,
      fat text ,
      ash text ,
      carbs text ,
      fiber text ,
      sugar text
    )
    ''')

query = 'insert into food VALUES (?,?,?,?,?,?,?,?,?,?)'

for line in open('ABBREV.txt'):
    fields = line.split("^");
    values = fields[1:11];
    curs.execute(query, values);

conn.commit();
conn.close();